Sub Connect2SpreadsheetThenPrint()
' Connect to Sales Rank Spreadsheet and Print Data
Dim cnxn As New ADODB.Connection
Dim rst1 As ADODB.Recordset

' Connect to Excel data source
cnxn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
     "Data Source=C:\APP Example Files\BookSalesRank.xls;" & _
     "Extended Properties=Excel 8.0;"
' Open a read-only recordset based on the Excel source file
Set rst1 = New ADODB.Recordset
rst1.CursorType = adOpenForwardOnly
rst1.LockType = adLockReadOnly
rst1.Open "ranks", cnxn, , , adCmdTable

'Print Fields from the first record
Debug.Print rst1.Fields(0).Value, rst1.Fields(1).Value, _
      rst1.Fields(2).Value, rst1.Fields(3).Value _
      rst1.Fields(4).Value, rst1.Fields(5).Value

'Clean up before exiting
rst1.Close
Set rst1 = Nothing
cnxn.Close
Set cnxn = Nothing

End Sub
